package singleton

import (
	"gopkg.in/yaml.v2"
	"os"
)

type config struct {
	Server struct {
		Port int    `yaml:"port"`
		Host string `yaml:"host"`
	} `yaml:"server"`

	Database struct {
		User     string `yaml:"user"`
		Password string `yaml:"password"`
		Name     string `yaml:"name"`
		Host     string `yaml:"host"`
		Port     int    `yaml:"port"`
	} `yaml:"database"`
	Rsa struct {
		PrivateKey     string            `yaml:"privateKey"` // 私钥
		PublicKey      string            `yaml:"publicKey"`  // 公钥
		PartnerPubKeys map[string]string // 合作方公钥
	} `yaml:"rsa"`
	SpecialUserList []string `yaml:"specialUsers"`
}

var cfg *config

func init() {
	cfg = &config{}
	filename := "./config.yaml"
	bytes, e := os.ReadFile(filename)
	if e != nil {
		panic(e)
	}
	if err := yaml.Unmarshal(bytes, &cfg); err != nil {
		panic(err)
	}
}

// 获取配置内容
func GetConfig() *config {
	return cfg
}
